| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| Lines | 62 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | |||
| 4 | describe('64-bit to bytes', function() { |
||
| 5 | |||
| 6 | let byteData = require('../../index.js'); |
||
| 7 | |||
| 8 | // 64-bit / 8 bytes |
||
| 9 | it('should turn 2 64-bit floats to 16 bytes (-1, 1)', function() { |
||
| 10 | assert.deepEqual(byteData.toBytes([1,-1], 64, {"base": 10}), |
||
| 11 | [0,0,0,0,0,0,240,63,0,0,0,0,0,0,240,191]); |
||
| 12 | }); |
||
| 13 | it('should turn 1 64-bit floats to 16 bytes hex (-1)', function() { |
||
| 14 | assert.deepEqual(byteData.toBytes([-1], 64, {"base": 16}), |
||
| 15 | ['00','00','00','00','00','00','f0','bf']); |
||
| 16 | }); |
||
| 17 | it('should turn 1 64-bit floats to 16 bytes hex (-0.5)', function() { |
||
| 18 | assert.deepEqual(byteData.toBytes([-0.5], 64, {"base": 16}), |
||
| 19 | ['00','00','00','00','00','00','e0','bf']); |
||
| 20 | }); |
||
| 21 | it('should turn 2 64-bit floats to 16 bytes (0s)', function() { |
||
| 22 | assert.deepEqual(byteData.toBytes([0, 0], 64, {"base": 10}), |
||
| 23 | [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]); |
||
| 24 | }); |
||
| 25 | it('should turn 3 64-bit floats to 16 bytes (0 0 1)', function() { |
||
| 26 | assert.deepEqual(byteData.toBytes([0, 0, 1], 64, {"base": 10}), |
||
| 27 | [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,63]); |
||
| 28 | }); |
||
| 29 | it('should turn 3 64-bit floats to 16 bytes (0 1 0)', function() { |
||
| 30 | assert.deepEqual(byteData.toBytes([0, 1, 0], 64, {"base": 10}), |
||
| 31 | [0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,63,0,0,0,0,0,0,0,0]); |
||
| 32 | }); |
||
| 33 | it('should turn 1 64-bit floats to 8 bytes (0.5)', function() { |
||
| 34 | assert.deepEqual(byteData.toBytes([0.5], 64, {"base": 10}), |
||
| 35 | [0,0,0,0,0,0,224,63]); |
||
| 36 | }); |
||
| 37 | it('should turn 1 64-bit float to 8 bytes (-0.5)', function() { |
||
| 38 | assert.deepEqual(byteData.toBytes([-0.5], 64, {"base": 10}), |
||
| 39 | [0,0,0,0,0,0,224,191]); |
||
| 40 | }); |
||
| 41 | it('should turn 1 64-bit float to 8 bytes (pi)', function() { |
||
| 42 | assert.deepEqual(byteData.toBytes([3.141592653589793], 64, {"base": 10}), |
||
| 43 | [24,45,68,84,251,33,9,64]); |
||
| 44 | }); |
||
| 45 | it('should turn 1 64-bit float to 8 bytes (pi)', function() { |
||
| 46 | assert.deepEqual(byteData.toBytes([9], 64, {"base": 10}), |
||
| 47 | [0,0,0,0,0,0,34,64]); |
||
| 48 | }); |
||
| 49 | it('should turn 1 64-bit float to 8 bytes (14)', function() { |
||
| 50 | assert.deepEqual(byteData.toBytes([31.41592653589793], 64, {"base": 10}), |
||
| 51 | [94,56,85,41,122,106,63,64]); |
||
| 52 | }); |
||
| 53 | it('should turn 1 64-bit float to 8 bytes (1)', function() { |
||
| 54 | assert.deepEqual(byteData.toBytes([314159265358979.3], 64, {"base": 10}), |
||
| 55 | [53,72,162,118,158,219,241,66]); |
||
| 56 | }); |
||
| 57 | it('should turn 1 64-bit float to 8 bytes (hex) (0)', function() { |
||
| 58 | assert.deepEqual(byteData.toBytes([0], 64, {"base": 16}), |
||
| 59 | ["00","00","00","00","00","00","00","00"]); |
||
| 60 | }) |
||
| 61 | it('should turn 1 64-bit float to 8 bytes hex (2)', function() { |
||
| 62 | assert.deepEqual(byteData.toBytes([2], 64, {"base": 16}), |
||
| 63 | ["00","00","00","00","00","00","00","40"]); |
||
| 64 | }); |
||
| 65 | }); |
||
| 66 |